import { get, post, put, del } from './index'

// 问题整改相关接口
export const problemApi = {
  // 获取问题列表
  getList: (params) => get('/api/problem/list', params),

  // 获取问题详情
  getDetail: (id) => get(`/api/problem/detail/${id}`),

  // 提交整改方案
  submitPlan: (data) => post('/api/problem/submit-plan', data),

  // 上传整改图片
  uploadImage: (data) => post('/api/problem/upload-image', data),

  // 确认整改完成
  confirmComplete: (id) => post(`/api/problem/confirm/${id}`),
}

// 问卷调查相关接口
export const questionnaireApi = {
  // 获取问卷列表
  getList: (params) => get('/api/questionnaire/list', params),

  // 获取问卷详情
  getDetail: (id) => get(`/api/questionnaire/detail/${id}`),

  // 提交问卷答案
  submit: (data) => post('/api/questionnaire/submit', data),

  // 获取问卷统计
  getStatistics: (id) => get(`/api/questionnaire/statistics/${id}`),
}

// 通知公告相关接口
export const noticeApi = {
  // 获取通知列表
  getList: (params) => get('/api/notice/list', params),

  // 获取通知详情
  getDetail: (id) => get(`/api/notice/detail/${id}`),

  // 标记为已读
  markAsRead: (id) => post(`/api/notice/read/${id}`),

  // 批量标记已读
  batchMarkAsRead: (ids) => post('/api/notice/batch-read', { ids }),
}

// 企业服务相关接口
export const enterpriseApi = {
  // 获取企业信息
  getInfo: () => get('/api/enterprise/info'),

  // 更新企业信息
  updateInfo: (data) => put('/api/enterprise/info', data),

  // 获取企业证照
  getCertificates: () => get('/api/enterprise/certificates'),

  // 上传企业证照
  uploadCertificate: (data) => post('/api/enterprise/upload-certificate', data),

  // 企业认证
  authenticate: (data) => post('/api/enterprise/authenticate', data),

  // 获取企业服务列表
  getServices: (params) => get('/api/enterprise/services', params),
}

// 文件上传相关接口
export const uploadApi = {
  // 通用文件上传
  uploadFile: (file, onProgress) => {
    const formData = new FormData()
    formData.append('file', file)

    return post('/api/upload/file', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
      onUploadProgress: onProgress,
    })
  },

  // 图片上传
  uploadImage: (file, onProgress) => {
    const formData = new FormData()
    formData.append('image', file)

    return post('/api/upload/image', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
      onUploadProgress: onProgress,
    })
  },

  // 删除文件
  deleteFile: (fileId) => del(`/api/upload/file/${fileId}`),
}

// 统计数据相关接口
export const statisticsApi = {
  // 获取首页统计数据
  getHomeStatistics: () => get('/api/statistics/home'),

  // 获取企业统计数据
  getEnterpriseStatistics: (params) =>
    get('/api/statistics/enterprise', params),

  // 获取政府统计数据
  getGovernmentStatistics: (params) =>
    get('/api/statistics/government', params),
}

export default {
  problemApi,
  questionnaireApi,
  noticeApi,
  enterpriseApi,
  uploadApi,
  statisticsApi,
}
